<template>
	<view>
		<u-navbar :background="{
					backgroundColor: 'rgb(25, 189, 93)',
				}" :is-back="false" :is-fixed="true" height="89" width="100%">
			<div class="title">免费开店</div>

			<view class="left-box" @tap="onClickLeft">
				<u-icon name="arrow-left" size="40" color="#FFF"></u-icon>
			</view>
		</u-navbar>


		<view class="topimg">
			<u-image src="../../static/newImg/midbartopimg.png" width="100%" height="342"></u-image>
		</view>

		<view class="center">
			<view class="centerItem" @click="navigatorTo('/pages/midbar/rzsqshangjiapage')"
				style="background: rgb(251, 191, 48);border-radius: 15rpx;">
				<view class="centerItem1">
					申请代理
				</view>
				<view class="centerItem2">
					自己做老板
				</view>
			</view>
			<view class="centerItem" @click="navigatorTo('/pages/gongyingshang/gysruzhushengqingpage')"
				style="background: rgb(32, 135, 232);border-radius: 15rpx;">
				<view class="centerItem1">
					商家入驻
				</view>
				<view class="centerItem2">
					企业品牌
				</view>
			</view>
		</view>
		<view class="midbarlast">
			声明：所有商家入驻，都必须取得国家相关法律资格才允许通过入驻，支持正品，杜绝损害消费者行为
		</view>


		<u-popup v-model="pupshow" mode="bottom" :closeable="false" :mask-close-able="true" border-radius="14">
			<view class="carshowview">
				<view class="popname">
					{{name}} 申请使用
				</view>

				<view class="popitem mt68">
					<view class="popitemname">
						头像
					</view>
					<view class="popitemcontent">
						<u-image :src="image" width="112rpx" height="112rpx"></u-image>
					</view>
				</view>

				<view class="popitem">
					<view class="popitemname">
						绑定号码
					</view>
					<view class="popitemcontent">
						{{phone}}
					</view>

				</view>

				<view class="popitem">
					<view class="popitemname">
						昵称
					</view>
					<view class="popitemcontent">
						{{name}}
					</view>

				</view>


				<view class="btnlist">
					<view class="btncancel" @click="pupshow = false">
						拒绝
					</view>
					<view class="btnOk" @click="handleOkCilck">
						允许
					</view>
				</view>
			</view>
		</u-popup>
	</view>
</template>

<script>
	import {

		getUserInfo
	} from "@/api/members.js";

	import {
		saleApply,
		saleAuthorize
	} from '@/api/user.js'
	import storage from "../../utils/storage.js";
	export default {
		data() {
			return {
				isClicking: false,
				pupshow: false,
				name: "",
				phone: "",
				image: ""


			}
		},
		onShow() {
			this.isClicking = false;

		},
		methods: {
			onClickLeft() {
				uni.navigateBack();
			},

			handleOkCilck() {
				uni.showLoading()
				saleAuthorize({
					id: storage.getUserInfo().id
				}).then(res => {
					if (res.code == '000000') {
						this.pupshow = false;
						uni.showToast({
							icon: 'none',
							title: "授权成功,即将跳转"
						})


						setTimeout(() => {
							uni.navigateTo({
								url: '/pages/business/index',
							});
						}, 1500)


					}
				})
				// uni.navigateTo({
				// 	url: '/pages/midbar/rzsqshangjiapage'
				// });

			},

			navigatorTo(url) {

				if (!this.$options.filters.isLogin('auth')) {
					return uni.showToast({
						title: "尚未登录，请先登录",
						icon: "none"
					})
				}
				if (this.isClicking) return
				this.isClicking = true
				uni.showLoading()
				getUserInfo({
					id: storage.getUserInfo().id
				}).then((user) => {

					this.isClicking = false

					if (user.code == '000000') {
						storage.setUserInfo({
							...user.data
						});
						storage.setHasLogin(true);
						const {
							storeId,
							type,
							name,
							image,
							phone
						} = user.data

						this.image = image;
						this.name = name;
						this.phone = phone || '18073096558'

						if (storeId == 0 || storeId == null) {

							if (url == '/pages/midbar/rzsqshangjiapage') {
								this.pupshow = true
							} else {
								return uni.navigateTo({
									url,
								});
							}

						} else {

							if (storeId == -1) {
								return uni.showToast({
									icon: "none",
									title: "正在审核中"
								})
							} else {
								if (type == 1) {
									// 分销

									if (url == '/pages/gongyingshang/gysruzhushengqingpage') {
										return uni.showToast({
											icon: "none",
											title: "您已经是分销商，无法申请供应商"
										})
									}
									return uni.navigateTo({
										url: '/pages/business/index',
									});
								} else {
									// 供应商
									if (url == '/pages/midbar/rzsqshangjiapage') {
										return uni.showToast({
											icon: "none",
											title: "您已经是供应商，无法申请分销商"
										})
									}

									return uni.navigateTo({
										url: '/pages/gongyingshang/index',
									});
								}
							}

						}
					}
				});
			},

		}
	}
</script>

<style scoped>
	.title {
		position: absolute;
		height: 89rpx;
		line-height: 89rpx;
		left: 50%;
		transform: translateX(-50%);
		font-family: PingFang;
		font-weight: bold;
		font-size: 40rpx;
		color: #FFFFFF;

	}

	.left-box {
		padding-left: 20rpx;
	}

	.center {
		width: 100%;
		padding: 35rpx;
		display: flex;
		flex-wrap: wrap;
		justify-content: space-between;
		align-content: space-between;

	}

	.centerItem {
		width: 332rpx;
		height: 294rpx;

		background: #FFFFFF;

		margin-bottom: 20rpx;
		padding-top: 87rpx;
	}

	.centerItem1 {
		width: 100%;
		font-family: Source Han Sans CN;
		font-weight: bold;
		font-size: 49rpx;
		color: #FFFFFF;
		text-align: center;

	}

	.centerItem2 {
		width: 100%;
		text-align: center;
		font-family: Source Han Sans CN;
		font-weight: 400;
		font-size: 32rpx;
		color: #FFFFFF;
		margin-top: 20rpx;
	}

	.midbarlast {
		width: 100%;
		padding: 0 60rpx;
		font-family: Microsoft YaHei;
		font-weight: 400;
		font-size: 20rpx;
		color: #909090;
		margin-top: 20rpx;
	}

	

	.carshowview {
		width: 100%;
		height: 728rpx;
		background: #FFFFFF;
		padding: 46rpx 47rpx;
	}
	
	


	.popname {

		height: 29rpx;
		font-family: Source Han Sans CN;
		font-weight: bold;
		font-size: 30rpx;
		color: #010101;
		line-height: 29rpx;
	}
	
	.mt68 {
		margin-top: 68rpx;
	}

	.popitem {
		width: 100%;
		height: 123rpx;
		border-bottom: 1rpx solid #f3f3f3;
		display: flex;
		align-items: center;
		position: relative;
	}

	.popitemname {
		width: 100rpx;
		height: 24rpx;
		font-family: Source Han Sans CN;
		font-weight: 400;
		font-size: 25rpx;
		color: #B0B0B0;
		margin-right: 100rpx;
	}

	.popitemcontent {

		font-family: Source Han Sans CN;
		font-weight: 500;
		font-size: 36rpx;
		color: #000000;
		position: absolute;
		top: 50%;
		left: 50%;
		transform: translate(-50%, -50%);
	}

	.btnlist {
		width: 100%;
		height: 84rpx;
		display: flex;
		align-items: center;
		justify-content: space-around;
		margin-top: 68rpx;


	}

	.btncancel {
		width: 250rpx;
		height: 84rpx;
		text-align: center;
		line-height: 84rpx;

		font-family: Source Han Sans CN;
		font-weight: 500;
		font-size: 38rpx;
		color: #07C160;
		background: rgb(242, 242, 242);
	}

	.btnOk {
		width: 250rpx;
		height: 84rpx;
		text-align: center;
		line-height: 84rpx;

		font-family: Source Han Sans CN;
		font-weight: 500;
		font-size: 38rpx;
		color: #FFFFFF;
		background: #07C160;
	}
</style>
